/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pageBeans;

import controller.StaffControllerEJB;
import entities.Applicant;
import entities.Application;
import entities.Application.Evaluation;
import entities.Application.Status;
import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

/**
 *
 * @author akefeli
 */
@Named(value = "staffPageBean")
@SessionScoped
public class StaffPageBean implements Serializable {

    @Inject
    private WizardPageBean wizardPageBean;
    @Inject
    private StaffControllerEJB staffControllerEJB;
    private String email;
    private Status status;
    private Evaluation evaluation;
    private boolean resultsRendered = false;
    private Applicant applicant;

    public String findApplicantByEmail() {
        applicant = staffControllerEJB.findApplicant(email);
        Application app = null;
        if (applicant != null) {
            System.out.println("1");
            app = applicant.getApplication();
        }
        if (applicant != null && app != null) {
            System.out.println("2");
            resultsRendered = true;
            wizardPageBean.staffLogged(app);
        } else if (applicant != null && app == null) {
            System.out.println("3");
            resultsRendered = false;
            String result = "Applicant does not have an application yet";
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, result, result);

            FacesContext.getCurrentInstance().addMessage(null, msg);

        } else {
            System.out.println("4");
            resultsRendered = false;
            String result = "Applicant not found";
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, result, result);

            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
        return null;
    }

    public String goToApplication() {
        return "wizard";
    }

    public Status getStatus() {
        if (staffControllerEJB != null) {
            this.status = staffControllerEJB.getStatus();
        }
        return status;
    }

    public void overrideStatus() {
        if (staffControllerEJB != null) {

            staffControllerEJB.overrideStatus(status);
        }
    }

    public void overrideEvaluation() {
        this.resultsRendered = true;
        if (staffControllerEJB != null) {

            staffControllerEJB.overrideEvaluation(evaluation);
        }
    }

    public String getEmail() {
        return email;
    }

    public Evaluation getEvaluation() {
        if (staffControllerEJB != null) {
            this.evaluation = staffControllerEJB.getEvaluation();
        }
        return evaluation;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public void setEvaluation(Evaluation evaluation) {
        this.evaluation = evaluation;
    }

    public boolean isResultsRendered() {
        return resultsRendered;
    }

    public void setResultsRendered(boolean resultsRendered) {
        this.resultsRendered = resultsRendered;
    }

    public Applicant getApplicant() {
        return applicant;
    }

    public void setApplicant(Applicant applicant) {
        this.applicant = applicant;
    }
}
